package com.waiting.leetcode;

/**
 * @Description
 * @Author bjweitingting
 * @Date 2019/3/19
 **/
public class RectangleArea223 {

    public static void main(String[] args) {
        RectangleArea223 test = new RectangleArea223();
        int result = test.computeArea(-2, -2, 2, 2, 3, 3, 4, 4);
        System.out.println(result);
    }

    public int computeArea(int A, int B, int C, int D, int E, int F, int G, int H) {
        int sum = computerArea(A, B, C, D) + computerArea(E, F, G, H);
        int length = 0, height = 0;
        if (G > A && C > E) {
            length = Math.min(C, G) - Math.max(A, E);
        }
        if (H > B && D > F) {
            height = Math.min(D, H) - Math.max(B, F);
        }
        return sum - Math.abs(length * height);
    }

    public int computerArea(int A, int B, int C, int D) {
        return Math.abs((C - A) * (D - B));
    }

}
